package com.yyq.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yyq.educms.client.courseClient;
import com.yyq.educms.entity.CrmBanner;
import com.yyq.educms.service.CrmBannerService;
import com.yyq.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author yyq
 * @since 2021-04-23
 */
@CrossOrigin //跨域
@RestController
@RequestMapping("/educms/crm-banner")
public class CrmBannerController {
    //注入servie
    @Autowired
    private CrmBannerService service;
    @Autowired
    private courseClient courseClient;
    //分页查询
    @GetMapping("/pageBanner/{cruent}/{limit}")
    public R pageBanner(@PathVariable long cruent,@PathVariable long limit){
        Page<CrmBanner> pages=new Page<>(cruent,limit);
        service.page(pages,null);


        return R.ok().data("total",pages.getTotal()).data("list",pages.getRecords());
    }
    //增加
    @PostMapping("/addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        String courseId =crmBanner.getLinkUrl();
        crmBanner.setLinkUrl("/course/"+courseId);
        service.save(crmBanner);
        return R.ok();
    }
    //删除
    @DeleteMapping("/deleteBannerByid/{id}")
    public R deleteBannerById(@PathVariable String id){
        service.removeById(id);
        return R.ok();
    }

    //修改
    @PostMapping("/updateBanner")
    public  R updateBannner(@RequestBody CrmBanner crmBanner){
        service.updateById(crmBanner);
        return R.ok();
    }

    //查询
    @GetMapping("/getBanner")
    public R getBanner(){
        List<CrmBanner> list = service.selcecTwoBanner();
        return R.ok().data("list",list);
    }
    //设置ｓｏｒｔ＝０
    @PostMapping("/setUnValid")
    public R setUnValid(@RequestBody CrmBanner banner){

        service.updateById(banner);
        return R.ok();
    }
}

